package mutsumimod.patches;

import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.*;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.powers.AbstractPower;

public class BasePatch {

    public static void addToBot(AbstractGameAction action) {
        AbstractDungeon.actionManager.addToBottom(action);
    }

    public static void addToTop(AbstractGameAction action) {
        AbstractDungeon.actionManager.addToTop(action);
    }

    public static void gainEnergy(int amount) {
        addToBot(new GainEnergyAction(amount));
    }

    public static void drawCard(int amount) {
        addToBot(new DrawCardAction(AbstractDungeon.player, amount));
    }

    public static void damageAllMonster(int baseDamage) {
        damageAllMonster(baseDamage, 1, AbstractGameAction.AttackEffect.SLASH_VERTICAL);
    }

    public static void damageAllMonster(int baseDamage, int damageTime) {
        damageAllMonster(baseDamage, damageTime, AbstractGameAction.AttackEffect.SLASH_VERTICAL);
    }

    public static void damageAllMonster(int baseDamage, int damageTime, AbstractGameAction.AttackEffect effect) {
        for (int i = 0; i < damageTime; i++) {
            addToBot(new DamageAllEnemiesAction(AbstractDungeon.player, baseDamage, DamageInfo.DamageType.NORMAL, effect));
        }
    }

    public static void damageMonster(int damage, AbstractMonster m) {
        damageMonster(damage, m, 1, com.megacrit.cardcrawl.actions.AbstractGameAction.AttackEffect.SLASH_VERTICAL);
    }

    public static void damageMonster(int damage, AbstractMonster m, int damageTime) {
        damageMonster(damage, m, damageTime, AbstractGameAction.AttackEffect.SLASH_VERTICAL);
    }

    public static void damageMonster(int damage, AbstractMonster m, int damageTime, AbstractGameAction.AttackEffect effect) {
        for (int i = 0; i < damageTime; i++) {
            addToBot(new DamageAction(m, new DamageInfo(AbstractDungeon.player, damage, DamageInfo.DamageType.NORMAL), effect));
        }
    }

    public static void gainBlock(int block) {
        addToBot(new GainBlockAction(AbstractDungeon.player, block));
    }

    public static void reducePowerAndRemove(int amount, String powerID) {
        if (AbstractDungeon.player.hasPower(powerID)) {
            AbstractPower p = AbstractDungeon.player.getPower(powerID);
            if (p.amount > amount) {
                addToBot(new ReducePowerAction(AbstractDungeon.player, AbstractDungeon.player, powerID, amount));
            } else {
                addToBot(new RemoveSpecificPowerAction(AbstractDungeon.player, AbstractDungeon.player, powerID));
            }
        }
    }

    public static void applyPowerSelf(AbstractPower power, int magicNumber) {
        if (magicNumber == 0) {
            addToBot(new ApplyPowerAction(AbstractDungeon.player, AbstractDungeon.player, power));
        } else {
            addToBot(new ApplyPowerAction(AbstractDungeon.player, AbstractDungeon.player, power, magicNumber));
        }
    }

    public static void applyPowerMonster(AbstractPower power, int magicNumber, AbstractMonster m) {
        if (magicNumber == 0) {
            addToBot(new ApplyPowerAction(m, AbstractDungeon.player, power));
        } else {
            addToBot(new ApplyPowerAction(m, AbstractDungeon.player, power, magicNumber));
        }
    }
}
